package com.xbts.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnCommonCloud;
import com.xbts.system.service.ICnCommonCloudService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 政务云Controller
 * @author xbts
 * @date 2023-08-23
 */
@Api(tags = "政务云")
@RestController
@RequestMapping("/system/common")
public class CnCommonCloudController extends BaseController {

    @Autowired
    private ICnCommonCloudService cnCommonCloudService;

    /**
     * 查询政务云模板列表
     */
    @ApiOperation("查询政务云模板列表")
//    @PreAuthorize("@ss.hasPermi('system:cloud:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnCommonCloud cnCommonCloud) {
        startPage(cnCommonCloud);
        return getDataTable(cnCommonCloudService.selectCnCommonCloudList(cnCommonCloud));
    }


    /**
     * 查询政务云列表
     */
    @ApiOperation("查询政务云列表")
    @PreAuthorize("@ss.hasPermi('system:cloud:list')")
    @PostMapping("/manager/list")
    public TableDataInfo managerList(@RequestBody CnCommonCloud cnCommonCloud) {
        startPage(cnCommonCloud);
        QueryWrapper<CnCommonCloud> queryWrapper = cnCommonCloud.queryWrapper();
        List<CnCommonCloud> list = cnCommonCloudService.list(queryWrapper);
        TableDataInfo dataTable = getDataTable(list);
        return dataTable;
    }

    /**
     * 查询热门政务云列表
     */
    @ApiOperation("查询热门政务云列表")
//    @PreAuthorize("@ss.hasPermi('system:cloud:list')")
    @GetMapping("/hostList")
    public TableDataInfo hostList() {
        List<CnCommonCloud> list = cnCommonCloudService.hostList();
        return getDataTable(list);
    }

    /**
     * 获取政务云详细信息
     */
    @ApiOperation("获取政务云详细信息")
    @ApiImplicitParam(name = "govId", value = "政务云ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:cloud:query')")
    @GetMapping(value = "/{govId}")
    public AjaxResult getInfo(@PathVariable("govId") String govId) {
        return success(cnCommonCloudService.selectCnCommonCloudByGovId(govId));
    }

    /**
     * 新增政务云
     */
    @ApiOperation("新增政务云")
    @PreAuthorize("@ss.hasPermi('system:cloud:add')")
    @Log(title = "政务云", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnCommonCloud cnCommonCloud) {
        return toAjax(cnCommonCloudService.insertCnCommonCloud(cnCommonCloud));
    }

    /**
     * 修改政务云
     */
    @ApiOperation("修改政务云")
    @PreAuthorize("@ss.hasPermi('system:cloud:edit')")
    @Log(title = "政务云", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CnCommonCloud cnCommonCloud) {
        return toAjax(cnCommonCloudService.updateCnCommonCloud(cnCommonCloud));
    }

    /**
     * 删除政务云
     */
    @ApiOperation("删除政务云")
    @ApiImplicitParam(name = "govIds", value = "政务云ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:cloud:remove')")
    @Log(title = "政务云", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> govIds) {
        return toAjax(cnCommonCloudService.deleteCnCommonCloudByGovIds(govIds));
    }

    /**
     * 获取政务云区域列表
     */
    @ApiOperation("获取政务云区域列表")
    @PreAuthorize("@ss.hasPermi('system:cloud:query')")
    @GetMapping(value = "/area")
    public AjaxResult areaList() {
        return success(cnCommonCloudService.areaList());
    }
}
